<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||	
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws. 
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.). 
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations). 
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Forum/classes/PhpFox_ComponentEditForum.class.php, $Author:  $ */



/** Forums list componment for Admin area.
 * 
 * @package module.forum
 * @version $Id: PhpFox_ComponentEditForum.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *   
 */
class PhpFox_Mod_Forum_ComponentEditForum extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
	    $oSrvForum = &$this->_oModule->getService('Forum');
	    /* @var $oSrvForum PhpFox_Mod_Forum_ServiceForum */
	    
	    $oReq = &App::getRequest();
	    /* @var $oReq Request */
	    
	    $oTxt = App::newObject('Text');
	    
	    $oForum = $this->_oModule->getItem('Forum');
        $iForumId = $oReq->getInt('id');
        if ($iForumId)
        {
            $oForum->load($iForumId);
        }
        else
        {
            $oForum->aData['forum_title'] = $oTxt->parseText($oTxt->rmSpecialChars($oReq->get('forum_title')));
        }
	    
        switch($oReq->getAction())
        {
            case 'create_forum':
                $oForum->aData['forum_title'] = $oTxt->parseText($oTxt->rmSpecialChars($oReq->get('forum_title')));
                $oForum->aData['forum_info']  = $oTxt->parseText($oReq->get('forum_info'));
                if ($oSrvForum->createForum($oForum, 'image'))
                {
                    App::gotoUrl('admin.sections.forum');
                }
                else
                {
                    $this->addErrors($oSrvForum->getErrors());
                }
                break;
                
            case 'edit_forum':
                $oForum->aData['forum_title'] = $oTxt->parseText($oTxt->rmSpecialChars($oReq->get('forum_title')));
                $oForum->aData['forum_info']  = $oTxt->parseText($oReq->get('forum_info'));                
                if ($oSrvForum->updateForum($oForum, 'image'))
                {
                    App::gotoUrl('admin.sections.forum');
                }
                else
                {
                    $this->addErrors($oSrvForum->getErrors());
                }
                break;                
        }

	    
        
	    $aForums = $oSrvForum->getForumList();

		$oTpl = &$this->_oModule->getTemplate();
		$oTpl->assign(array(
		    'aForum'       => $oForum->aData,
		    'aErrors'      => $this->getErrors(),
		    'iForumId'     => $oReq->getInt('id'),
		    'sForumPicUrl' => App::getParam('forum.pic.url'),
		));
		$srcHtml = $oTpl->fetch('EditForum.html');
		return $srcHtml;
	}

}
?>